<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="cn.school.mybatis.utils.MyBatisUtil" %>
<%@ page import="cn.school.mybatis.dao.AdminDao" %>
<%@ page import="cn.school.mybatis.pojo.Admin" %><%--
  Created by IntelliJ IDEA.
  User: zhaoyang
  Date: 2020/8/5
  Time: 6:31 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册用户</title>
</head>
<body>

<%
    request.setCharacterEncoding("utf-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String checkpwd = request.getParameter("checkpwd");
    out.println(username);
    out.println(password);
    out.println(checkpwd);

    int result=0;
    if (password.equals(checkpwd)) {
        SqlSession sess = MyBatisUtil.getSqlSession();
        AdminDao adminDao = sess.getMapper(AdminDao.class);
        result = adminDao.add(new Admin(username, password));
        sess.commit();
        System.out.println(result + "条增加成功！");
        MyBatisUtil.close(sess);
    } else {
        out.print("<script>alert('两次输入的密码不一致！');history.back();</script>");
        return;
    }
%>
<script>
    if (confirm(<%=result%>+"条用户注册成功！")) {
        location.replace("login.jsp");
    } else {
        location.replace("register.jsp");
    }
</script>
</body>
</html>
